/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cubelabs.nexus.controller;

import cubelabs.nexus.entity.Institute;
import cubelabs.nexus.entity.User;
import cubelabs.nexus.service.InstituteService;
import java.util.Locale;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author chaitanya
 */
@Controller
public class InstituteController {
	@Autowired
	private InstituteService instituteService;
	
	@RequestMapping(value = "/createInstitute", method = RequestMethod.POST)
	public @ResponseBody long createInstitute(@ModelAttribute("institute") Institute ins,Locale locale, Model model,HttpSession session){
		ins.setUser((User)session.getAttribute("user"));
		return instituteService.createInstitute(ins);
	}
	
	@RequestMapping(value = "/editInstitute", method = RequestMethod.POST)
	public ModelAndView editInstitute(@ModelAttribute("institute") Institute ins,Locale locale, Model model,HttpSession session){
		ins.setUser((User)session.getAttribute("user"));
		instituteService.editInstitute(ins);
		return new ModelAndView();
	}
	
	@RequestMapping(value = "/findInstitute", method = RequestMethod.POST)
	public @ResponseBody Institute editInstitute(@ModelAttribute("instituteId") long instituteId,Locale locale, Model model,HttpSession session){
		return instituteService.fetchInstitute(instituteId);
	}
	
	
}
